﻿Public Class ObjektMultiValue
    Inherits Objekt2D
    Public Values As ObjektValueSchieber() = {}
    Dim LetztesValues As Integer = 0
    Public Property LetztesValue() As Integer
        Get
            Return LetztesValues
        End Get
        Set(ByVal value As Integer)
            LetztesValues += 1
            If LetztesValues > Values.Length - 1 Then
                LetztesValues = 0
            End If
        End Set
    End Property
    Dim MinValue, MaxValue As Integer
    Public Sub New(ByVal MinValue As Integer, ByVal MaxValue As Integer, ByVal ZahlderValues As Integer, ByVal Position As Point, ByVal Breite As Integer, ByVal ValueAbstand As Integer, ByVal Fixed As PointF, Optional ByVal Handler As ObjektPanel = Nothing)
        MyBase.New("", New Rectangle, Position, Fixed, Handler)
        Array.Resize(Values, ZahlderValues)
        Dim R As Integer
        Me.MinValue = MinValue
        Me.MaxValue = MaxValue
        Dim Startvalue As Integer = Math.DivRem(MaxValue, ZahlderValues, R)
        For I = 0 To ZahlderValues - 1
            Values(I) = New ObjektValueSchieber("ValueRegler", MinValue, MaxValue, Breite, Position, Startvalue, Fixed, , , "%", Handler)
            Position.Y += ValueAbstand
        Next
        Dim I2 As Integer = 0
        While R > 0
            Values(I2).Value += 1
            I2 += 1
            If I2 > Values.Length - 1 Then
                I2 = 0
            End If
            R -= 1
        End While
    End Sub
    Public Overrides Sub Malen()
        'MyBase.Malen()
        For I = 0 To Values.Length - 1
            Dim AltesValue As Integer = Values(I).Value
            Values(I).Malen()
            ValuesAendern(AltesValue, I)
        Next
    End Sub
    Private Sub ValuesAendern(ByVal AltesValue As Integer, ByVal Value As Integer)
        Dim Z As Integer = Values(Value).Value - AltesValue
        Dim Aenderung As Integer = -1
        If Z < 0 Then
            Aenderung = 1
            Z *= -1
        End If
        For I = 1 To Z
            Dim B As Boolean = False
            While B = False
                If Values(LetztesValue).Value + Aenderung < MinValue Or Values(LetztesValue).Value + Aenderung > MaxValue Then
                    B = False
                    LetztesValue = 1
                Else
                    Values(LetztesValue).Value = Aenderung
                    LetztesValue = 1
                    B = True
                End If
            End While
        Next
    End Sub
    Public Function GetValue(ByVal Value As Integer) As Integer
        Return Values(Value).Value
    End Function
    Public Sub SetValue(ByVal Value As Integer, ByVal Wert As Integer, ByVal AutoComplet As Boolean)
        If AutoComplet = False Then
            Values(Value).SetValue(Wert)
        Else
            Dim Alt As Integer = Values(Value).Value
            Values(Value).SetValue(Wert)
            ValuesAendern(Alt, Value)
        End If
    End Sub
    Public Overrides Sub ChangeWindowSize(ByVal PosChange As System.Drawing.Point)
        For Each Value In Values
            Value.ChangeWindowSize(PosChange)
        Next
    End Sub

    Public Overrides Function Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean

    End Function

    Public Overrides Function KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean

    End Function

    Public Overloads Overrides Function MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        For I = 0 To Values.Length - 1
            Values(I).MouseDown(e.X, e.Y)
        Next
    End Function

    Public Overloads Overrides Function MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        For I = 0 To Values.Length - 1
            Dim AltesValue As Integer = Values(I).Value
            Values(I).MouseMove(e.X, e.Y)
            ValuesAendern(AltesValue, I)
        Next
    End Function

    Public Overloads Overrides Function MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As String
        'Aber wir muessen evtl. Die Values verschieben
        For I = 0 To Values.Length - 1
            Values(I).MouseUp(e.X, e.Y)
        Next
        Return ""
    End Function

    Public Overloads Overrides Function MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean

    End Function
End Class
